let config = { duration: 30 * 1000, format: "mp3", audioSource: "auto" }
const RecorderManager = wx.getRecorderManager();

function LRecorder(Context) {
  this.enable = true;
  let doSth = ()=>{};
  this.complete = (sth) => { doSth = sth };
  let Callback, getAvailableAudioSourcesComplete = (res) => {
    if (res.errMsg !== "getAvailableAudioSources:ok") this.enable = false; 
    if (!this.enable) wx.showToast({ title: '未找到录音设备', icon: "none" }); 
    doSth();
  };
  wx.getAvailableAudioSources({ complete: getAvailableAudioSourcesComplete });
}
module.exports.LRecorder = LRecorder;

function start(){
  if (!this.enable) return wx.showToast({ title: '未找到录音设备', icon: "none" });
  RecorderManager.onStart(()=>{
    wx.hideLoading();
    wx.showLoading({ title: '录音中~松开停止', }); 
  })
  wx.showLoading({ title: '准备录音', }); 
  let startOptions = config;
  RecorderManager.start(startOptions);
}
LRecorder.prototype.start = start;

function stop(Callback) {
  if (!this.enable) return wx.showToast({ title: '未找到录音设备', icon: "none" });
  wx.hideLoading();
  RecorderManager.onStop(Callback);
  let startOptions = config;
  RecorderManager.stop();
}
LRecorder.prototype.stop = stop;